package com.sitech.portal.menus.action;

import com.opensymphony.xwork2.ActionSupport;
import com.sitech.ibnms.util.JSONUtil;
import com.sitech.portal.menus.form.UserShortcut;
import com.sitech.portal.menus.service.UserShortcutService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Created by leo on 15/6/3.
 */
public class UserShortcutAction extends ActionSupport {

    @Autowired
    private UserShortcutService shortcutService;
    private List<UserShortcut> shortcutList;
    private String shortcutPath;
    private UserShortcut shortcut;

    public String getUserShortcuts() {
        shortcutList = shortcutService.getShortcutList();
        return SUCCESS;
    }

    public String removeShortcut() {
        shortcutService.deleteShortcut(shortcutPath);
        return SUCCESS;
    }

    public String addShortcut() {
        shortcutService.addShortcut(shortcut);
        return SUCCESS;
    }

    public List<UserShortcut> getShortcutList() {
        return shortcutList;
    }

    public void setShortcutPath(String shortcutPath) {
        this.shortcutPath = shortcutPath;
    }

    public void setShortcut(String shortcutJson) {
        shortcut = JSONUtil.fromJSON(shortcutJson, UserShortcut.class);
    }

    public void setShortcut(UserShortcut shortcut) {
        this.shortcut = shortcut;
    }
}
